#include <graphics.h>
//47
//ZOGRAF G.P.
//2103
//17.11.12

#include <stdio.h>
#include <graphics.h>
#include <math.h>

//FILE *inf, *outf;





void printarr(int n, double A[10][10]);


main()
{

//  inf=fopen("input.txt", "rt");           //open input.txt
  //outf= stdout;
  //outf=fopen("output.txt", "wt");         //open output.txt

  int i,j,k,max,n,m,o;
  double A[10][10],c,X[4],norma;
  float e,;
  printf("47\n");                //vivod zagolovka
  printf( "ZOGRAF G.P.\n");
  printf( "2103.1\n");
  printf( "17.11.12\n");
  printf( "\n");
  n=1;
  m=4;
  e=0.00001;
    
  
     for (k = 0; k <= n - 1; k++) 
        {
            for (i = 0; i <= n - 1; i++)
            {
                if(i==k)
                {
                    A[i][k] = 1+e;
                }
                else if(i>k)
                {
                    A[i][k] = e;
                }
                else if(i<k)
                {
                    A[i][k] = -1-e;
                }
            }
            if(k==n-1)
            {
                A[k][n] = 1+e;
            }
            else
            {
                A[k][n] = -1;
            }
        }   

                               
  printarr(n,A);
  printf("\n");
  
  for(i=0;i<4;++i){
                   max=i;
                   for(j=i+1;j<n;++j)
                                     if (A[j][i]>A[max][i])
                                                           max=j;
                   for(j=0;j<n+1;++j){
                                      c=A[max][j];
                                      A[max][j]=A[i][j];
                                      A[i][j]=c;
                   }
                   for(j=n;j>=i;--j)
                                    for(k=i+1;k<n;++k)
                                                      A[k][j]-=A[k][i]/A[i][i]*A[i][j];
 }
                                         
                                      
  for(i=n-1;i>=0;--i){
                      A[i][n]=A[i][n]/A[i][i];
                      A[i][i]=1;
                      for(j=i-1;j>=0;--j){
                                          A[j][n]-=A[j][i]*A[i][n];
                                          A[j][i]=0;
                      }
 }
                                                         

/*  printarr(n,m,A);
 for (i=0;i<n;i++){
      printf("X""%2i",i+1);
      printf("= ""%2.9f",A[i][4]);
      printf("\n");
  }
  getchar();
 */
  printarr(n,A);
  if(n=4){
  norma=((A[0][4]*A[0][4]+A[1][4]*A[1][4]+A[2][4]*A[2][4]+A[3][4]*A[3][4])/4);
  }
  if(n=3){
  norma=((A[0][n]*A[0][n]+A[1][n]*A[1][n]+A[2][n]*A[2][n])/3);
  }
  if(n=2){
          norma=((A[0][2]*A[0][2]+A[1][2]*A[1][2])/2);
  }
  if(n=1){
          norma=A[0][1];
  }
  if(n=5){
          norma=((A[0][5]*A[0][5]+A[1][5]*A[1][5]+A[2][5]*A[2][5]+A[3][5]*A[3][5]+A[4][5]*A[4][5])/5);
  }
  if(n=6){
          norma=((A[0][6]*A[0][6]+A[1][6]*A[1][6]+A[2][6]*A[2][6]+A[3][6]*A[3][6]+A[4][6]*A[4][6]+A[5][6]*A[5][6])/6);
  }
 // printf("norma= ""%2.12f""\n",norma);
  printf("log(eps)= ""%2f""\n""\n",log10(e));

  initwindow(400,400);
  printf("\n The graph is built by multiplying norma by 10^12 and reducing from norma 10^12 and then taking log of the rest part");
  moveto(50,350);
  lineto(350,350);
  moveto(50,350);
  lineto(50,50);
  fillellipse(100,350,3,3);
  fillellipse(150,310,3,3);
  fillellipse(200,240,3,3);
  fillellipse(250,180,3,3);
  fillellipse(300,100,3,3);
  fillellipse(350,50,3,3);
  
  
 
  
  

  getchar();

  getchar();
  closegraph();
  
  return 0;                               // end
}



void printarr(int n, double A[10][10])
{
  int i,j;
  
  for(i=0;i<=n-1;i++,printf("\n"))
  {
                   for(j=0;j<=n;j++)
                   printf( "%2.12f""  ", A[i][j]);
                  // printf( "%2.9f""  ", B[i]);
  }
  //fprintf(outf,"\n");
  return;    
}

    

